home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13730 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Reverting of big array ?
  5. Date: Tue, 26 Mar 1996 15:16:31 -0800
  6. Organization: systems hk
  7. Message-ID: <31587ACF.59D9@teleport.com>
  8. References: <Pine.SOL.3.91.960326132111.6385A-100000@evolution>
  9. NNTP-Posting-Host: ip-pdx02-38.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (WinNT; I)
  14.  
  15. Thomas wrote:
  16. > I need to revert an array (of chars).
  17. > I used the folowing code:( l=length of array)
  18. >   char *rev=new char[l+1];
  19. >   for(i=l-1,j=0;i>=0;i--,j++)  rev[j]=seq[i];
  20. >   rev[j]='\0';
  21. > this code works, but is terribly slow, when using an string with
  22. > size ~ 6000.
  23. > doing the same with the unix command 'rev' takes 1/2 second.
  24. > Any ideas  ???Thomas,
  25. It might not be much faster, but I usually use the following:
  26.  
  27.   for( i=0; i<numChars/2; i++ )
  28.     strChars[i] = strChars[numChars-i-1];
  29.  
  30. Also, your compiler might support a 'string-reverse' function.
  31. Yours, Geoff Houck
  32.